<?php 
function get_assign_info($input,$method,$id) {
	
	include(CONFIG.'config.php');
	mysql_select_db($database, $connection);
	
	$query_info = "SELECT $method FROM assignments WHERE id='$id'";
	$info = mysql_query($query_info, $connection) or die(mysql_error());
	$row_info = mysql_fetch_assoc($info);
	
	if ($method == "assign_rubrics") {
		do { 
			$a = explode(",", $row_info['assign_rubrics']);
			foreach ($a as $value) { if ($value == $input) return TRUE;	}
		} while ($row_info = mysql_fetch_assoc($info));
	}	
	
	if ($method == "assign_wp") {
		do { 
			$a = explode(",", $row_info['assign_wp']);
			foreach ($a as $value) { if ($value == $input) return TRUE;	}
		} while ($row_info = mysql_fetch_assoc($info));
	}
}
?>
<script language="Javascript">
function submitForm() {
tinyMCE.triggerSave();
document.forms[0].submit();
</script>
<?php if (($go == "draft") || ($go == "missing") || ($go == "make-changes")) { ?>
<p><?php if (($action == "edit") || ($go == "missing")) echo "Edit"; else echo "Add"; ?> Module <?php echo $mid; ?>, Assignment <?php echo $mid.".".$row_assignments['assign_num']; ?> content to <?php echo $row_courses['jiu_course_id'].": ".$row_courses['name']; ?>.</p>
<?php if ($go == "missing") echo "<div class='error_msg'>Please complete both the overview and procedure sections below.</div>"; ?>
<div class="stacked">
<span class="icon"><img src="images/disk.png" border="0" align="absmiddle" /></span><input id="Submit" name="Submit" type="submit" class="save_progress_form" value="<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>">
</div>
<table class="dataTable">
    <tr style="background-color: <?php echo $color1; ?>">
        <td class="dataLabel">Assignment Title:</td>
        <td class="data">
        <input id="assign_title" name="assign_title" type="text" size="50" value="<?php echo $row_assignments['assign_title']; ?>">
        </td>
    </tr>
    <tr style="background-color: <?php echo $color2; ?>">
    	<td class="help_text" colspan="2"><p>Compose or copy/paste the Assignment's overview below. Use the &quot;format&quot; drop-down list to define headings if needed. Click the "<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>"  button above to save your work.</p>
        </td>
    </tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Assignment Overview:</td>
    <td class="data">
    <textarea id="assign_overview" name="assign_overview" type="text" cols="110" rows="15"><?php if (($action == "edit") || ($row_assignments['assign_overview'] != "")) echo $row_assignments['assign_overview']; ?></textarea>
    </td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
    	<td class="help_text" colspan="2"><p>Compose or copy/paste the Assignment's procedure below.</p></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">Assignment Procedure:</td>
    <td class="data">
    <textarea id="assign_procedure" name="assign_procedure" type="text" cols="110" rows="25"><?php if (($action == "edit") || ($row_assignments['assign_procedure'] != "")) echo $row_assignments['assign_procedure']; ?></textarea>
    </td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
  <td class="dataLabel">Points Possible:</td>
  <td class="data"><input id="assign_points" name="assign_points" type="text" size="10" value="<?php echo $row_assignments['assign_points']; ?>"></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
    	<td class="help_text" colspan="2"><p>Choose the appropriate JIU Workplace Competencies that apply to this assignment.</p></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">Workplace Competencies:</td>
    <td class="data">
    	<table class="dataTableCompact">
    <?php do { ?>
    		<tr>
            	<td><input id="assign_wp" name="assign_wp[]" type="checkbox" value="<?php echo $row_wp['id']; ?>" <?php if ($row_wp['id'] <= "3") echo "CHECKED"; elseif (($action == "add") || ($action == "edit") || ($action == "review")) { if (get_assign_info($row_wp['id'],"assign_wp",$id)) echo "CHECKED"; } ?> /></td>
                <td class="data"><?php echo "<strong>".$row_wp['wp_name']."</strong> &mdash; ".$row_wp['wp_info']; ?></td>
            </tr>
    <?php } while ($row_wp = mysql_fetch_assoc($wp)); ?>
    	</table>
    </td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
    	<td class="help_text" colspan="2"><p>Choose the appropriate JIU rubrics that apply to this assignment.</p></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Rubrics:</td>
    <td class="data">
    	<table class="dataTableCompact">
    <?php do { ?>
    		<tr>
            	<td><input id="assign_rubrics" name="assign_rubrics[]" type="checkbox" value="<?php echo $row_rubrics['id']; ?>" <?php if (($action == "add") || ($action == "edit") || ($action == "review")) { if (get_assign_info($row_rubrics['id'],"assign_rubrics",$id)) echo "CHECKED"; } ?> /></td>
                <td class="data"><strong><?php if ($row_rubrics['rubric_path'] != "") echo "<a href='".$row_rubrics['rubric_path']."' target='_blank'>".$row_rubrics['rubric_name']."</a>"; else echo $row_rubrics['rubric_name']; ?></strong> &mdash; <?php echo $row_rubrics['rubric_info']; ?></td>
          </tr>
    <?php } while ($row_rubrics = mysql_fetch_assoc($rubrics)); ?>
    	</table>
    </td>
</tr>
</table>
<input name="assign_num" type="hidden" value="<?php echo $row_assignments['assign_num']; ?>" />
<input name="vid" type="hidden" value="<?php if ($action == "add") echo "1"; elseif (($action == "edit") && ($go == "make-changes")) echo ($row_assignments['vid'] + 1); elseif (((($action == "edit") || ($action == "review")) || ($go == "missing")) && ($vid != "default")) echo ($row_assignments['vid']);  ?>" />
<div class="stacked">
<span class="icon"><img src="images/disk.png" border="0" align="absmiddle" /></span><input id="Submit" name="Submit" type="submit" class="save_progress_form" value="<?php if (($action == "edit") || ($go == "missing")) echo "Update"; else echo "Save"; ?>">
</div>
<?php } ?>




<?php if ($go == "confirm") { ?>
<div class="error_msg">Assignment content saved.</div>
<p>Are you finished with adding/editing this assignment? A preview version is below for your review.</p>
<div class="stacked">
	<span class="icon"><img src="images/page_edit.png" border="0" align="absmiddle" /></span><a href="index.php?section=module_assignment&amp;action=review&go=draft&amp;view=course_detail&amp;dbTable=assignments&amp;cid=<?php echo $cid; ?>&amp;mid=<?php echo $mid; ?>&amp;vid=<?php echo $row_assignments['vid']; ?>&amp;id=<?php echo $id; ?>&amp;modal_window=<?php echo $modal_window; ?>">No, I wish to continue adding to or editing this assignment</a>
</div>
<div class="stacked">
	<span class="icon"><img src="images/tick.png" border="0" align="absmiddle" /></span><a href="index.php?section=module_assignment&amp;action=review&go=finished&amp;view=course_detail&amp;dbTable=assignments&amp;cid=<?php echo $cid; ?>&amp;mid=<?php echo $mid; ?>&amp;vid=<?php echo $row_assignments['vid']; ?>&amp;id=<?php echo $id; ?>&amp;modal_window=<?php echo $modal_window; ?>">Yes, I have finished</a>
</div>
<?php } ?>


<?php if ($go == "finished") { ?>
<div class="error_msg">Assignment content saved and a new version has been created (Version <?php echo $vid; ?>).</div>
<p>The assignment content is below.</p>
<?php } ?>
<?php if (($go == "confirm") || ($go == "finished")) { ?>
<div id="preview">
<h1><?php echo "Assignment ".$mid.".".$row_assignments['assign_num'].": ".$row_assignments['assign_title']; ?></h1>
<?php echo $row_assignments['assign_overview']; ?>
<h2>Procedure</h2>
<?php echo $row_assignments['assign_procedure']; ?>
<h2>Evaluation</h2>
<p>Your assignment is worth <?php echo $row_assignments['assign_points']; ?> points.</p>
<?php if ($row_assignments['assign_rubrics'] != "") { ?>
<p>Your assignment will be evaluated based upon the following rubrics:</p>
<ul>
<?php 
$a = explode(",",$row_assignments['assign_rubrics']);
foreach ($a as $value) {
	$query_rubrics = "SELECT * FROM rubrics WHERE id='$value'";
	$rubrics = mysql_query($query_rubrics, $connection) or die(mysql_error());
	$row_rubrics = mysql_fetch_assoc($rubrics);
	
	echo "<li>"; 
	if ($row_rubrics['rubric_path'] != "") echo "<a href='".$row_rubrics['rubric_path']."' target='_blank'>".$row_rubrics['rubric_name']."</a>"; else echo $row_rubrics['rubric_name'];
	echo "</li>";
}
?>
</ul>
<?php } ?>
<h2>Workplace Compentencies</h2>
<p>Your assignment will be evaluated based upon the following criteria:</p>
<ul>
<?php 
$a = explode(",",$row_assignments['assign_wp']);
foreach ($a as $value) {
	$query_wp = "SELECT * FROM workplace_comps WHERE id='$value'";
	$wp = mysql_query($query_wp, $connection) or die(mysql_error());
	$row_wp = mysql_fetch_assoc($wp);
	
	echo "<li><strong>".$row_wp['wp_name']."</strong> &mdash; ".$row_wp['wp_info']."</li>";
}
?>
</ul>
</div>
<?php } ?>


